#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const int N=200050;
int n,m;
vector<int> g[N];
int degree[N];
int a,b;
int cnt;
int ans;
bool vis[N];
int gidx[N];
int flag;
void dfs(int u){
    vis[u]=true;
    if(degree[u]!=2){
        flag=1;
    }
    int l=g[u].size();
    for(int i=0;i<l;i++){
        if(vis[g[u][i]]){
            continue;
        }
        dfs(g[u][i]);
    }
}
int main(void){
    //freopen("data.txt","r",stdin);
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d%d",&a,&b);
        g[a].push_back(b);
        g[b].push_back(a);
        degree[a]++;
        degree[b]++;
    }
    for(int i=1;i<=n;i++){
        flag=0;
        if(!vis[i]){
            dfs(i);
            if(!flag){
                ans++;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}
